<?php

declare (strict_types=1);
namespace App\Model;

/**
 * @property int $id
 * @property int $tpl_id 模板id
 * @property int $rule_id 区域模板id
 * @property int $city_id 城市id
 * @property int $pid 省id
 * @property string $area_json 地区id列表
 */
class DeliveryRuleArea extends CloudBase
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fly_delivery_rule_area';
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [];
    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'tpl_id' => 'integer', 'rule_id' => 'integer', 'city_id' => 'integer', 'area_json' => 'array'];

    public function children(){
        return $this->hasMany(get_class($this),'province_id','province_id')
            ;
    }
    public function province_child(){
        return $this->hasMany(Areainfo::class,'pid','province_id')
            ->select('pid','id');
            ;
    }
    public function city_child(){
        return $this->hasMany(Areainfo::class,'pid','city_id')
            ->select('pid','id');
//            ->select('areainfo.id');
        ;
    }
}